<?php 
global $options;

if ( is_category( 'publications' ) ) {
	$postid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_title = 'Publications'" );
	wp_redirect( get_permalink( $postid ) ); exit;
}

if ( is_category( 'people' ) ) {
	$staff_id = get_cat_ID( 'Staff' );
	$staff_link = get_category_link( $staff_id );
	wp_redirect( $staff_link ); exit;
}

if ( isset( $_GET['projects'] ) ) {
	 include 'single-projects.php';
} else

foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');

$currCat = get_the_category();
$parent = get_cat_name($currCat[0]->category_parent);
if ( is_category( 'individual-projects' ) ) { 
	$cat_id = get_cat_ID( 'Projects' );
	wp_redirect( get_category_link( $cat_id ) ); exit;
}

//redirect to child if is archive for top-level parent
if ( is_category( $parent ) ) { 
	first_subcat_redirect();
}
			
get_header(); ?>


  <div id="content">
    <div class="wrap">

      <div class="column column-narrow">
      
		<?php  
	
			echo "<p class='heading'>".$parent."</p>";
    	
			//list all categories, posts listed underneath, hide empty
			list_cat_posts_all() 
		?>      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Archive Pages') ) : ?>&nbsp;<?php endif; ?>
        
      </div><!-- end .column-narrow -->
      
      <div class="column column-content column-double column-last">
	  	<div id="crumbs">
			<!--?php the_breadcrumb(); ?-->
			<?php
				$args = array(
					'prefix' => '<p>',
					'suffix' => '</p>',
					'title' => __( '', 'breadcrumbs-plus' ),
					'home' => __( 'Home', 'breadcrumbs-plus' ),
					'sep' => '»',
					'front_page' => false,
					'bold' => true,
					'show_blog' => false,
					'echo' => true,
					'singular_post_taxonomy' => 'category',
				);
				breadcrumbs_plus( $args );
			?>
		</div>
      
		<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
		<?php /* If this is a category archive */ if (is_category()) { ?>
		<h1><?php single_cat_title(); ?></h1>
		<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
		<h1>Archive for: <?php single_tag_title(); ?></h1>
		<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
		<h1>Archive for <?php the_time('F jS, Y'); ?></h1>
		<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
		<h1>Archive for <?php the_time('F, Y'); ?></h1>
		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
		<h1>Archive for <?php the_time('Y'); ?></h1>
		<?php /* If this is an author archive */ } ?>
	  
      <div class="posts">
	<?php
	if (is_category( )) {
		$cat = get_query_var('cat');
		$currentcat = get_category ($cat);
		if ($currentcat->slug == 'latest-news') {
			//the_time(__('F jS, Y', 'kubrick'));
		}
	}
	//else {
	?>
<!-- START regular archive -->
	<?php
	 
	  	wp_reset_query();
		
		if ( is_category( 'latest-news' ) ) {
			$wp_query->set('order', 'DESC');
		}
		else {
			wp_reset_query();
			$wp_query->set('orderby', 'menu_order');
			$wp_query->set('order', 'ASC');
		}
		$wp_query->get_posts();  
	
	  $i = 0;
	  if (have_posts()) : while (have_posts()) : the_post();
	  $i++;
	  update_post_caches($posts);
	  ?>
	      
	        <div class="post">
	        
	        <?php 
			unset($img);
	
					if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
							$attachedFile = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
	            $img = $attachedFile[0]; 
							}
					
					else{ 
					 
	          if ($proud_cf_use == 'Yes')
	          {
	            $img = get_post_meta($post->ID, $proud_cf_photo, true);
	          } // if CF used
	          else
	          {
	            if (!$img)
	            {
	              $img = catch_that_image($post->ID);
	            }
	          } // if CF not used
	        }
	          
	          if ($img)
	          {
	            ?>
	            <div class="thumb"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?h=80&amp;w=120&amp;zc=1&amp;src=<?php echo $img ?>" alt="<?php the_title(); ?>" class="bordered" /></a></div>
	            <?php 
	          }
	
	    ?>	
	          <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
	          
	          <div class="info">
	          	<p><em>
	          	<?php 
	          		if ( is_category( 'latest-news' ) ) {
	          			the_time(__('F jS, Y', 'kubrick'));
	          		}
	          	?>
	          	</p></em>
	          	<?php the_excerpt(); ?>
	          </div>
	<?php //} ?>
<!-- END regular archive -->
        
          <div class="clear">&nbsp;</div>  

        </div><!-- end .post -->

        <?php endwhile; 
        
        else:
        
        ?>
        <h2>Sorry, there are no posts in this category.</h2>
        <?php
        
        endif; ?>

      <div class="navigation">
      <p><span class="older"><?php next_posts_link('&lt; older entries') ?></span>  <span class="latest"><?php previous_posts_link('newer entries &gt;') ?></span></p>
      </div>

      </div><!-- end .posts -->
      
      </div><!-- end .column-content -->
      
      <div class="clear">&nbsp;</div>

    </div><!-- end .wrap -->
  </div><!-- end #content -->

<?php get_footer(); ?>
